/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.zzdt4j.threadpool.dynamic.api;

import java.util.HashMap;
import java.util.Map;

/**
 * Thread-pool dynamic refresh
 *
 * @author by <a href="mailto:ligang941012@gmail.com">gang.Li</a>
 * @since 2023/10/19 2:18
 */
public interface ThreadPoolDynamicRefresh {

    /**
     * Register configuration center event listener.
     */
    default void registerListener() {
    }

    /**
     * Constructs a bootstrap properties object.
     * This method, based on the provided configuration information map, creates and returns
     * an instance of BootstrapPropertiesInterface.
     *
     * @param configInfo A map containing key-value pairs of configuration data.
     *                   The parameter allows for any type of keys and values, with specific usage
     *                   dependent on the implementation.
     * @return BootstrapPropertiesInterface An instance of the bootstrap properties object.
     * In this default implementation, null is always returned. Subclasses should override
     * this method to provide a concrete implementation.
     */
    default BootstrapPropertiesInterface buildBootstrapProperties(Map<Object, Object> configInfo) {
        return null;
    }

    /**
     * Dynamic refresh of configuration center data changes.
     *
     * @param content changed data
     */
    default void dynamicRefresh(String content) {
    }

    /**
     * Dynamic refresh of configuration center data changes.
     *
     * @param configContent     change data
     * @param newValueChangeMap new value change map
     */
    default void dynamicRefresh(String configContent, HashMap<String, Object> newValueChangeMap) {

    }

    /**
     * Refreshes dynamically based on provided content and a map of new value changes.
     * This method performs a dynamic refresh operation depending on the specific implementation of this interface.
     *
     * @param content           The original content or identifier used for refreshing.
     * @param newValueChangeMap A map containing the new value changes, where keys represent attribute names and values represent the updated attribute values. This is used to update internal states or trigger specific refresh logic.
     */
    default void dynamicRefresh(String content, Map<String, Object> newValueChangeMap) {
    }

    /**
     * Dynamically refreshes configuration.
     * This method is used to refresh the configuration dynamically based on the provided configuration file type,
     * new content, and a map of value changes.
     * It updates the configuration for a specific configuration file type by replacing the original content with the new one
     * and modifies the configuration items according to the provided mapping.
     *
     * @param configFileType    The type of the configuration file, which is used to identify the configuration file to be refreshed.
     * @param content           The new content of the configuration file to replace the existing content.
     * @param newValueChangeMap A mapping containing configuration item names and their new values to update specific configuration items.
     *                          Each entry in this map represents a new value for a configuration item, allowing the update of multiple items.
     *                          <p>
     *                          Note: This method is a default method, defined in an interface but without a concrete implementation.
     *                          The actual implementation logic should be completed in the implementing class according to specific requirements.
     */
    default void dynamicRefresh(String configFileType, String content, Map<String, Object> newValueChangeMap) {
    }
}
